import request from "../utils/http.ts";
import {getToken} from "../utils/common.ts";
import TOKEN_ENUM from "../access/tokenEnums.ts";
import {UserLoginToken} from "../type/user";
//获取用户信息
// @ts-ignore
let promise;
export const refreshToke = async () => {
    // @ts-ignore
    if (promise) {
        return promise;
    }
    promise = new Promise(async (resolve) => {
        const res = await request<UserLoginToken>({
            url: '/auth/refresh',
            method: 'GET',
            headers: {
                token: getToken(TOKEN_ENUM.REFRESH_TOKEN)
            },
            // @ts-ignore
            __isRefresh: true
        });
        resolve(Object.keys(res.data).length !== 0);
    });
    promise.finally(() => {
        promise = null;
    });
    return promise;
}
export const isRefreshRequest = async (config: any) => {
    return config.__isRefresh;
}